package com.ly.mpayment.persist.service.uporderlog;

import java.io.Serializable;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.ly.mpayment.persist.entity.UpOrderLog;
import com.ly.mpayment.persist.hibernate.Page;
import com.ly.mpayment.persist.service.AbstractService;

@Service
public class UpOrderLogServiceImpl extends AbstractService<UpOrderLog, Serializable> implements IUpOrderLogService {

	@Override
	public boolean addUporderlog(UpOrderLog log) {
		if(log != null){
			this.saveOrUpdate(log);
			return true;
		}
		return false;
	}

	@Override
	public boolean updateUporderlog(UpOrderLog log) {
		if(log != null){
			this.saveOrUpdate(log);
			return true;
		}
		return false;
	}

	@Override
	public UpOrderLog findById(String id) {
		return this.findUnique("select u from UpOrderLog u where u.uporderloguuid = ?", id);
	}


	@Override
	public Page<UpOrderLog> findPageUporderlog(Map<String, Object> parameters, int start, int pageSize) {
		String hql = "select u from UpOrderLog u left join fetch u.upOrder up where  1 = 1 #[ and up.upphonenum = :phoneNum]#";
		if(parameters.containsKey(":starttime")){
			hql += " and u.createtime >= '"+parameters.get(":starttime") +"' ";
			parameters.remove(":starttime");
		}
		if(parameters.containsKey(":endtime")){
			hql += " and u.createtime <= '"+parameters.get(":endtime") +"' ";
			parameters.remove(":endtime");
		}
		hql += " #[and up.userOrder.useruuid = :useruuid]# order by u.createtime desc";
		return this.findPageByNamed(hql, parameters, start, pageSize);
	}

}
